package com.ruoyi.project.kefu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.kefu.domain.AppKefu;
import com.ruoyi.project.kefu.service.IAppKefuService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 客服配置Controller
 * 
 * @author wyh
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/kefu/kefu")
public class AppKefuController extends BaseController
{
    @Autowired
    private IAppKefuService appKefuService;

    /**
     * 查询客服配置列表
     */
    @PreAuthorize("@ss.hasPermi('kefu:kefu:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppKefu appKefu)
    {
        startPage();
        List<AppKefu> list = appKefuService.selectAppKefuList(appKefu);
        return getDataTable(list);
    }

    /**
     * 导出客服配置列表
     */
    @PreAuthorize("@ss.hasPermi('kefu:kefu:export')")
    @Log(title = "客服配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppKefu appKefu)
    {
        List<AppKefu> list = appKefuService.selectAppKefuList(appKefu);
        ExcelUtil<AppKefu> util = new ExcelUtil<AppKefu>(AppKefu.class);
        util.exportExcel(response, list, "客服配置数据");
    }

    /**
     * 获取客服配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('kefu:kefu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appKefuService.selectAppKefuById(id));
    }

    /**
     * 新增客服配置
     */
    @PreAuthorize("@ss.hasPermi('kefu:kefu:add')")
    @Log(title = "客服配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppKefu appKefu)
    {
        return toAjax(appKefuService.insertAppKefu(appKefu));
    }

    /**
     * 修改客服配置
     */
    @PreAuthorize("@ss.hasPermi('kefu:kefu:edit')")
    @Log(title = "客服配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppKefu appKefu)
    {
        return toAjax(appKefuService.updateAppKefu(appKefu));
    }

    /**
     * 删除客服配置
     */
    @PreAuthorize("@ss.hasPermi('kefu:kefu:remove')")
    @Log(title = "客服配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appKefuService.deleteAppKefuByIds(ids));
    }
}
